// components/filedlist/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {

    matchfiledlist: {
      type: [],
      value: [],
      observer: function (newVal, oldVal) {
        console.log(newVal);
        this._matchfiledlistpropertyChange(newVal, oldVal);

      } // 属性被改变时执行的函数（可选），也可以写成在methods段中定义的方法名字符串, 如：'_propertyChange'

    },
    matchinfo: {
      type: Object,
      value: undefined,
      observer: function (newVal, oldVal) {

        this._matchinfopropertyChange(newVal, oldVal);

      } // 属性被改变时执行的函数（可选），也可以写成在methods段中定义的方法名字符串, 如：'_propertyChange'
    },

    TOP:{
      type:Int16Array,
      value:999,
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    currentTab: 0,
    currentpageheight: 0
  },

  /**
   * 组件的方法列表
   */
  methods: {
    //打开playerscorecard 页面 
    _openplayerCard(e) {
      this.setData({
        selectplayerid: e.currentTarget.dataset.id,
        teamorplayer: 0
      });
      var playername = e.currentTarget.dataset.playername;
      let id = (this.data.teamorplayer == 0) ? this.data.selectplayerid : this.data.selectteamid;
      // 微信小程序中是通过triggerEvent来给父组件传递信息的
      this.triggerEvent('_openplayerCard', {
        playerorteam: this.data.teamorplayer,
        selectid: id,
        playername: playername,
        matchinfo: JSON.stringify(this.data.matchinfo)
      }) // 将参数的形式传递给父组件

    },

    fillheight() {
      var that = this;
      var obj = this.createSelectorQuery().select("#vfiledlist" + that.data.currentTab);

      obj.boundingClientRect(function (rect) {
        if (rect == null || rect.height == null) {
          return;
        }
        var fullheight = wx.getSystemInfoSync().windowHeight;
        var windowswidth = wx.getSystemInfoSync().windowWidth;
        var pixelRatio = windowswidth / 750; // wx.getSystemInfoSync().pixelRatio;
        console.log("pixelRatio");
        console.log(pixelRatio);
      

          that.setData({
            currentpageheight: (rect.height) / pixelRatio  // 节点的高度
          });
          console.log(rect.height);
          console.log(that.data.currentpageheight);
        

      }).exec();
    },

    _openteamCard:function(e){
      this.setData({
        selectteamid: e.currentTarget.dataset.teamid,
        teamorplayer: 0
      });
      var teamname = e.currentTarget.dataset.teamname;
      let selectteamid =e.currentTarget.dataset.teamid;
      // 微信小程序中是通过triggerEvent来给父组件传递信息的
      this.triggerEvent('_openteamCard', {
        
        selectid: selectteamid,
        teamname: teamname,
        matchinfo: JSON.stringify(this.data.matchinfo)
      }) // 将参数的形式传递给父组件
    },


    //  tab切换逻辑
    swichNav: function (e) {
      var that = this;
      if (that.data.currentTab === e.target.dataset.current) {

        return false;
      } else {
        that.setData({
          currentTab: e.target.dataset.current
        })

        that.fillheight();
      }
    },

    bindChange: function (e) {
      var that = this;
      that.setData({
        currentTab: e.detail.current
      });
      that.fillheight();
    },

    _matchinfopropertyChange(newVal, oldVal) {
      console.log("_matchinfopropertyChange",newVal);
        this.fillheight();
    },

    _matchfiledlistpropertyChange(newVal, oldVal) {

      this.fillheight();
    }
  }
})